<template>
  <Modal
    ref="modal"
    title="审核"
    width="600px"
    @show="getDetail(value.id)"
  >
    <template #reference>
      <slot />
    </template>
    <el-form label-width="100px">
      <el-form-item
        label="企业名称"
        prop="companyName"
      >
        <el-input
          v-model.trim="form.companyName"
          disabled
        />
      </el-form-item>
      <el-form-item
        label="开票金额"
        prop="price"
      >
        <el-input
          :value="`￥ ${((form.price || 0) / 100).toFixed(2)}`"
          disabled
        />
      </el-form-item>
      <el-form-item
        label="发票抬头"
        prop="companyTitle"
      >
        <el-input
          v-model.trim="form.companyTitle"
          disabled
        />
      </el-form-item>
      <el-form-item
        label="纳税人识别号"
        prop="identifier"
      >
        <el-input
          v-model.trim="form.identifier"
          disabled
        />
      </el-form-item>
      <el-form-item
        label="公司地址"
        prop="mailAddress"
      >
        <el-input
          v-model.trim="form.mailAddress"
          disabled
        />
      </el-form-item>
      <el-form-item
        label="公司电话"
        prop="mailPhone"
      >
        <el-input
          v-model.trim="form.mailPhone"
          disabled
        />
      </el-form-item>
      <el-form-item
        label="开户银行"
        prop="bank"
      >
        <el-input
          v-model.trim="form.bank"
          disabled
        />
      </el-form-item>
      <el-form-item
        label="银行账号"
        prop="bankAcc"
      >
        <el-input
          v-model.trim="form.bankAcc"
          disabled
        />
      </el-form-item>
    </el-form>
    <template #footer>
      <div class="text-center">
        <el-button
          type="danger"
          class="w-40"
          @click="handleReject"
        >
          审核驳回
        </el-button>
        <el-button
          type="primary"
          @click="handleResolve"
        >
          已开票，填写信息
        </el-button>
      </div>
    </template>
  </Modal>
</template>

<script>
import { isSuccess } from '@/utils/common'
import { invoiceAudit } from '@/api/invoice'
export default {
    components: {
        Modal: () => import('@/components/Modal'),
    },
    props: {
        value: {
            type: Object,
            default() {
                return {}
            },
        },
    },
    data() {
        return {
            form: {},
        }
    },
    watch: {},
    methods: {
        async getDetail(id) {
            const res = await this.$store.dispatch('invoice/detail', {
                invoiceId: id,
            })
            if (isSuccess(res)) {
                this.form = res.data
            }
        },
        handleResolve() {
            this.$refs.modal.hide()
            this.$emit('resolve')
        },
        async handleReject() {
            const res = await invoiceAudit({
                id: this.value.id,
                state: 'reject',
            })
            if (isSuccess(res)) {
                this.$message.success('驳回成功')
                this.$refs.modal.hide()
                this.$store.dispatch('invoice/list')
            }
        },
    },
}
</script>